﻿
namespace n_NotePanel
{
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using n_GUIcoder;
using n_MyPanel;
using n_GVar;
using n_MyButton;
using n_MyLabel;
using n_MyTextBox;
using n_GNote;
using n_NoteForm;

//*****************************************************
//变量面板类
public class NotePanel : MyPanel
{
	GNote owner;
	
	public MyTextBox NameTextBox;
	public MyButton NameButton;
	public MyButton DeleteButton;
	public MyButton EditButton;
	public MyLabel MyLabelType;
	
	//构造函数
	public NotePanel( GNote v ) : base()
	{
		owner = v;
		
		BackBrush = new SolidBrush( Color.FromArgb( 200, 150, 200, 150 ) );
		
		/*
		NameTextBox = new MyTextBox( this, owner.Name );
		NameTextBox.X = 5;
		NameTextBox.Y = 5;
		NameTextBox.Width = 100;
		NameTextBox.MyTextChanged += new MyTextBox.deleTextChanged( NameTextBoxTextChanged );
		this.AddControl( NameTextBox );
		*/
		
		DeleteButton = new MyButton( this );
		DeleteButton.Text = "删除";
		DeleteButton.X = 5;
		DeleteButton.Y = 40;
		DeleteButton.MyMouseDown += new MyButton.deleMouseDown( DeleteButtonMouseDown );
		this.AddControl( DeleteButton );
		
		EditButton = new MyButton( this );
		EditButton.Text = "编辑";
		EditButton.X = 70;
		EditButton.Y = 40;
		EditButton.MyMouseDown += new MyButton.deleMouseDown( EditButtonMouseDown );
		this.AddControl( EditButton );
		
		this.Width = 114;
		this.Height = 80;
	}
	
	//文字改变事件
	void NameTextBoxTextChanged( object sender )
	{
		if( this.NameTextBox.Text != "" ) {
			owner.Name = this.NameTextBox.Text;
		}
	}
	
	//删除键鼠标按下事件
	void DeleteButtonMouseDown( object sender )
	{
		if( G.SimulateMode ) {
			n_Debug.Warning.WarningMessage = "仿真模式下无法删除模块, 请先结束仿真";
			return;
		}
		if( MessageBox.Show( "您确定删除当前组件吗?", "组件删除确认", MessageBoxButtons.OKCancel ) == DialogResult.OK ) {
			owner.Remove();
		}
	}
	
	//编辑键鼠标按下事件
	void EditButtonMouseDown( object sender )
	{
		if( owner.isCode ) {
			if( G.UserCodeBox == null ) {
				G.UserCodeBox = new n_UserCodeForm.UserCodeForm();
			}
			string s = G.UserCodeBox.Run( owner, owner.Value, owner.isCX );
			if( s != null ) {
				owner.Value = s;
				owner.isCX = G.UserCodeBox.isCX();
				((GNote)owner).RefreshHeight();
			}
		}
		else {
			if( G.NoteBox == null ) {
				G.NoteBox = new n_NoteForm.NoteForm();
			}
			string s = G.NoteBox.Run( owner, owner.Value );
			if( s != null ) {
				owner.Value = s;
				((GNote)owner).RefreshHeight();
			}
		}
	}
}
}



